package com.superteam.zzl.adapter.RecommendFragmentAdapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.superteam.zzl.activity.MainActivity;
import com.superteam.zzl.activity.R;
import com.superteam.zzl.model.RecommendFragment.MainData;

import java.util.ArrayList;

/**
 * Created by zhang on 2017/1/9.
 */

/**
 * 推荐页面 本地专题适配器
 */

public class LvLocalAdapter extends BaseAdapter {
    private Context context;
    private ArrayList<MainData.ZhuangtiBean> list;

    public LvLocalAdapter(Context context, ArrayList<MainData.ZhuangtiBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        //Log.e("data","local"+list.size());
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if(convertView == null){
            convertView = View.inflate(context, R.layout.recommendfragment_item_lv_local,null);
            vh = new ViewHolder();
            vh.iv = (ImageView) convertView.findViewById(R.id.iv_lv_local);
            vh.tv_title = (TextView)convertView.findViewById(R.id.tv_title_lv_local);
            vh.tv_tag = (TextView)convertView.findViewById(R.id.tv_tag_lv_local);
            vh.tv_like = (TextView)convertView.findViewById(R.id.tv_good_lv_local);
            convertView.setTag(vh);
        }else{
            vh = (ViewHolder) convertView.getTag();
        }
        vh.tv_title.setText(list.get(position).getTitle());
        vh.tv_tag.setText(list.get(position).getTags());
        vh.tv_like.setText(list.get(position).getLike()+"人喜欢");
        //Log.e("data","local ==== "+list.get(position).getTitle());
        Glide.with(context).load(list.get(position).getSrc()).into(vh.iv);
        MainActivity.handler1.sendEmptyMessage(0x2011);
        return convertView;
    }

    class ViewHolder{
        ImageView iv;
        TextView tv_title,tv_tag,tv_like;

    }
}
